/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package diagram.handles;

import diagram.Node;
import diagram.locations.FlexibleRelativeLocation;
import diagram.locations.VerticalLineLocation;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Stroke;

/**
 *
 * @author Jelle
 */
public class InputHandle extends SquareHandle {

    private int minSize = 20; // default
    private int xi;
    private int yi;
    private int wi;
    private int hi;

    public InputHandle() {
    }

    public InputHandle(Node baseNode, int minnSize) {

        super(baseNode , new VerticalLineLocation(new FlexibleRelativeLocation(baseNode.getUpperLeft(), -31, 0),new FlexibleRelativeLocation(baseNode.getUpperLeft(), -31, 0), new FlexibleRelativeLocation(baseNode.getLowerRight(), -31, -15)), minnSize);
        //this.setUpperLeft(new FlexibleRelativeLocation(baseNode.getUpperLeft(), -31, 5));
        //this.setLowerRight(new FlexibleRelativeLocation(this.getUpperLeft(), 30, 15));
//     * @param baseNode the baseNode to set
//     */
//    public void setBaseNode(Node baseNode) {
//        super.setLocation(new LowerRightLocation(new AbsoluteLocation(baseNode.getLowerRight().getX()+10, baseNode.getLowerRight().getY()+10), new RigidRelativeLocation(new AbsoluteLocation(baseNode.getUpperLeft().getX() - (minSize / 2), baseNode.getUpperLeft().getY() - (minSize / 2)), minSize, minSize)));
//        super.setSize(minSize);
//        super.setBaseNode(baseNode);
//    }
        

    }

    /**
     * @param minSize the minSize to set
     */
    public void setMinSize(int minSize) {
        this.minSize = minSize;
    }

    public void paint(Graphics2D g)
	{
		Color oldColor = g.getColor();
        Stroke oldStroke = g.getStroke();

//        xi = getBaseNode().getUpperLeft().getX()-30-1;
//        yi = getBaseNode().getUpperLeft().getY()+5;
        xi = this.getUpperLeft().getX();
        yi = this.getUpperLeft().getY();
        wi = 30;
        hi = 15;

        g.setColor(Color.WHITE);
        g.fillRect(xi, yi, wi, hi);
        if (((Node)getBase()).isSelected()) {
            g.setColor(Color.RED);
        } else {
            g.setColor(Color.BLACK);
        }

        //g.setStroke(new BasicStroke(2));
        g.drawRect(xi, yi, wi, hi);
        if (highlighted)
			g.drawRect(xi-3, yi-3, wi+6, hi+6);

        g.setStroke(oldStroke);
		g.setColor(oldColor);
	}

    public Rectangle getRectangle() {
        return new Rectangle(getX(), getY(), getWidth(), getHeight());
    }

    public boolean contains(int x, int y) {
        return getRectangle().contains(x, y);
    }

    public int getX() {
        return xi;
    }

    public int getY() {
        return yi;
    }

    public int getWidth() {
        return wi;
    }

    public int getHeight() {
        return hi;
    }
}
